package servlet;

import entity.MeetingRoom;
import service.MeetingRoomService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/listRooms") // 映射URL
public class ListMeetingRoomServlet extends HttpServlet {
    private MeetingRoomService roomService = new MeetingRoomService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1. 调用业务层获取所有会议室
        List<MeetingRoom> roomList = roomService.findAllRooms();
        // 2. 存入请求域，转发到首页
        req.setAttribute("roomList", roomList);
        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }
}